package com.emp.dao;

import java.util.List;

import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import com.emp.bean.Dept;
import com.emp.bean.Emp;



//部门Dao
@Repository
public interface DeptDao {
   
	  //依据部门编号，查询部门
	 @Select(" select * from t_dept where deptno=#{deptno}")
	 @Results(id="deptMap",value={
			 @Result(id=true,column="deptno",property="deptno"),
			 @Result(column="dname",property="dname"),
			 @Result(column="location",property="location"),
			 @Result(column="deptno",property="emps",many
			 =@Many(select="com.emp.dao.EmpDao.queryByDeptno",fetchType=FetchType.LAZY))
	 })                                                    
	  Dept queryByDeptno(String deptno) throws Exception;
	 
	 @Select(" select * from t_dept ")
	 @Results(id="deptMap2",value={
			 @Result(id=true,column="deptno",property="deptno"),
			 @Result(column="dname",property="dname"),
			 @Result(column="location",property="location"),
			 @Result(column="deptno",property="emps",many
			 =@Many(select="com.emp.dao.EmpDao.queryByDeptno"))
	 })  //因为返回值要封装成JSON对象,所以不能用懒加载
	 List<Dept> queryAll() throws Exception;
	 

}
